Theory

The second law of thermodynamics states that for an isolated system its entropy, S, increases until the system reaches equilibrium, that is:

∆S ⋝ 0,

where the = sign means the thermodynamic equilibrium.

Statistical mechanics asserts that, once equilibrium is attained, the molecules of the system are distributed over the respective energy levels accordingly Boltzmann's distribution:

ni / N = exp(-β εi) / ∑exp(-β εi) ; (i=0, 1, 2, ...)

where ni is the number of molecules at level i of energy εi, N the total number of molecules, and β = 1/kT, being k Boltzmann's constant and T the absolute temperature of the system.
Additionally, statistical mechanics links the entropy to the number of microstates, W, of a molecular distribution, through Boltzmann's equation:

S/k = ln W,

where, for distinguishable molecules with non-degenerate energy levels,

W = N! / n0! n1!...ni!...

In the present simulation, N independent, and distinguishable molecules, are initially set at the same energy level and by means of susequent random collisions they are allowed to jump to other levels so that the total energy of the system is kept constant.

References:

- "Elements of Statistical Thermodynamics", L. K. Nash, 2nd edition, Dover Publications, Inc., New York,1974.


- "Statistical Thermodynamics", A. Maczek, Oxford Chemistry Primers, Oxford University Press, 1998.

- "An Introduction to Computer Simulation Methods. Applications to Physical Systems", H. Gould, J. Tobochnik, W. Christian, 3rd edition, Addison Wesley, New York, 2007.